#include "TextureFactory.h"

TextureFactory* TextureFactory::instance = 0;

using namespace std;

TextureFactory::TextureFactory(){
}

void TextureFactory::destroy(){
	if(TextureFactory::instance!=NULL)
		delete TextureFactory::instance;
	TextureFactory::instance = NULL;
}

TextureFactory::~TextureFactory(){}


TextureFactory* TextureFactory::getInstance(){
	if(!TextureFactory::instance)
		TextureFactory::instance = new TextureFactory();
	return TextureFactory::instance;
}

Texture* TextureFactory::getTexture(MapList* parameters) throw (InvalidTextureException){
	std::string id;
	std::string path;

	try{
		CustomizedMap *mapTexture = parameters->getElement(parameters->getType());

		id = mapTexture->getAttribute("id");

		path = mapTexture->getAttribute("path");
	
		delete mapTexture;

		return new Texture(id, path);

	}catch(AttributeNotFoundException &e){
		throw InvalidTextureException("La textura no pudo ser creada faltan parametros");
	}catch(ImagePathNotFoundException &e){
		throw InvalidTextureException("La textura no pudo ser creada el Path de la imagen no se encontro");
	}
	
}